package com.bdv.md.model;

import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

@Entity
@Table (name = "transaction")
@DynamicInsert
@DynamicUpdate
public class Transaction extends BaseObject {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3L;
	private String txId;
	private Integer type;
	private Timestamp requestTime;
	private Timestamp responseTime;
	private MapTbl meter;
	
	private Integer retry;
	private String status;

	@Id
	@Column(name = "TX_ID")
	public String getTxId() {
		return txId;
	}
	public void setTxId(String txId) {
		this.txId = txId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "MAP_ID", nullable = false)
	public MapTbl getMeter() {
		return meter;
	}
	public void setMeter(MapTbl meter) {
		this.meter = meter;
	}
	
	@Column(name = "TYPE")
	public Integer getType() {
		return type;
	}
	public void setType(Integer type) {
		this.type = type;
	}
	
	@Column(name = "REQUEST_TIME")
	public Timestamp getRequestTime() {
		return requestTime;
	}
	public void setRequestTime(Timestamp requestTime) {
		this.requestTime = requestTime;
	}
	
	@Column(name = "RESPONSE_TIME")
	public Timestamp getResponseTime() {
		return responseTime;
	}
	public void setResponseTime(Timestamp responseTime) {
		this.responseTime = responseTime;
	}

	@Column(name = "RETRY")
	public Integer getRetry() {
		return retry;
	}
	public void setRetry(Integer retry) {
		this.retry = retry;
	}

	@Column(name = "STATUS")
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((meter == null) ? 0 : meter.hashCode());
		result = prime * result
				+ ((requestTime == null) ? 0 : requestTime.hashCode());
		result = prime * result
				+ ((responseTime == null) ? 0 : responseTime.hashCode());
		result = prime * result + ((retry == null) ? 0 : retry.hashCode());
		result = prime * result + ((status == null) ? 0 : status.hashCode());
		result = prime * result + ((txId == null) ? 0 : txId.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Transaction other = (Transaction) obj;
		if (meter == null) {
			if (other.meter != null)
				return false;
		} else if (!meter.equals(other.meter))
			return false;
		if (requestTime == null) {
			if (other.requestTime != null)
				return false;
		} else if (!requestTime.equals(other.requestTime))
			return false;
		if (responseTime == null) {
			if (other.responseTime != null)
				return false;
		} else if (!responseTime.equals(other.responseTime))
			return false;
		if (retry == null) {
			if (other.retry != null)
				return false;
		} else if (!retry.equals(other.retry))
			return false;
		if (status == null) {
			if (other.status != null)
				return false;
		} else if (!status.equals(other.status))
			return false;
		if (txId == null) {
			if (other.txId != null)
				return false;
		} else if (!txId.equals(other.txId))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "Transaction ["
				+ (txId != null ? "txId=" + txId + ", " : "")
				+ (type != null ? "type=" + type + ", " : "")
				+ (requestTime != null ? "requestTime=" + requestTime + ", "
						: "")
				+ (responseTime != null ? "responseTime=" + responseTime + ", "
						: "") + (meter != null ? "meter=" + meter + ", " : "")
				+ (retry != null ? "retry=" + retry + ", " : "")
				+ (status != null ? "status=" + status : "") + "]";
	}

	
	
}
